package com.itheima.health.controller;

import com.itheima.health.dto.UserDto;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.service.User2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户模块管理")
@RequestMapping("user")
public class UserController {

    @Reference
    private User2Service user2Service;

    @PostMapping("findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询所有人员信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return new Result(user2Service.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "新增人员或更新人员信息",notes = "未携带id时新增，携带id时更新")
    public Result saveOrUpdate(@RequestBody UserDto userDto){
        return new Result(user2Service.saveUpdate(userDto));
    }

    @GetMapping("findRidByUid/{uid}")
    @ApiOperation(value = "userVO",notes = "根据人员id查询角色id,以及人员详情，用做数据回显")
    public Result findRidByUid(@PathVariable("uid") Integer uid){
        return new Result(user2Service.findByUid(uid));
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除功能",notes = "根据人员id删除人员信息")
    public Result deleteById(@PathVariable("id") int id){
        Boolean flag = user2Service.deleteById(id);
        return new Result(flag);
    }
}
